/**
 * 
 */
package au.com.carboncycle.gb.engine;

/**
 * @author Brendan
 *
 */
public class GameClock {

    private long lastTime = System.nanoTime();
    private long gameStartedAt = System.nanoTime();
    private long gameTime = 0;
    private long unprocessedTime = 0;
    private long now = lastTime;
    
    
    public void tick() {
        long now = System.nanoTime();
        gameTime = now - gameStartedAt;
        unprocessedTime += now - lastTime;
        lastTime = now;
    }
    
    public long getNow() {
    	return now;
    }
    
    public long getLastTime() {
    	return lastTime;
    }
    
    public long getGameTime() {
    	return gameTime;
    }
    
    public boolean isUnprocessed() {
    	return unprocessedTime > 0;
    }

	public void runDown() {
		unprocessedTime -= 1000000000 / 60;
	}
    
	public void endTick() {
		unprocessedTime = 0;
	}
	
}
